/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.cashmate.struts;


import com.cashmate.hibernate.dao.AreaDAO;
import com.cashmate.hibernate.pojo.Branches;
import com.opensymphony.xwork2.ActionSupport;
import java.util.ArrayList;
import java.util.List;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;

/**
 *
 * @author Lee
 */
public class GetAreasApp extends ActionSupport {

    private AreaDAO ard = (AreaDAO) ServletActionContext.getServletContext().getAttribute("areaDAO");
    private List<String> areaList;

    public List<String> getAreaList() {
        return areaList;
    }

    @Action(value = "/get-areas", results = {
        @Result(name = "input", location = "/loanapplication.jsp"),
        @Result(name = "success", location = "/loanapplication.jsp"),
        @Result(name = "error", location = "/loanapplication.jsp")
    })
    @Override
    public String execute() {
        try {
            Branches b = (Branches) ServletActionContext.getRequest().getSession().getAttribute("branch");
//            System.out.println("BRANCH!!! " + b.getBranchcode());
            areaList = new ArrayList<String>();
            for (int i = 0; i < ard.getAll().size(); i++) {
//            if(ard.getAll().get(i).getBranches().getBranchcode().equals(b.getBranchcode())){
                String areacode = ard.getAll().get(i).getAreacode();
                areaList.add(areacode);
//                System.out.println(areacode);
//            }
            }
        } catch (Exception e) {
            e.printStackTrace();
            return ERROR;
        }
//        System.out.println("AREALIST: " + areaList.toString());
        return SUCCESS;
    }
}
